//
//  UIBarButtonItem+Extension.swift
//  LH-Swift-WeiBo
//
//  Created by liuhao on 16/9/22.
//  Copyright © 2016年 liuhao. All rights reserved.
//

import UIKit


extension UIBarButtonItem{

    //添加一个构造方法
    convenience init(title : String = "",imageName : String? = nil,target :Any?, action :Selector) {
        //实例化button
        let btn = UIButton()
        
        btn.setTitle(title, for: .normal)
        btn.setTitleColor(UIColor.lightGray, for: .normal)
        btn.setTitleColor(UIColor.orange, for: .highlighted)
        
        //设置字体
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        
        if imageName != nil {
            
            btn.setImage(UIImage(named :imageName!), for: .normal)
            btn.setImage(UIImage(named :imageName! + "_highlighted"), for: .highlighted)
        }
        btn.sizeToFit()
        
        
        //添加点击事件
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        self.init()
        //给当前对象 设置自定义视图
        self.customView = btn
        
        
        
    }


}
